package com.winning.sjzc.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.winning.sjzc.common.dao.CommomMapper;
import com.winning.sjzc.common.entity.po.SysZcjgEntity;
import com.winning.sjzc.common.entity.vo.JgTreeEntity;
import com.winning.sjzc.common.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName CommonServiceImpl
 * @Description TODO
 * @Author WJX
 * @Date 2020/3/2 17:12
 **/
@Service
@Slf4j
public class CommonServiceImpl implements CommonService {

    @Autowired
    private CommomMapper commomMapper;

    @Override
    public List<JgTreeEntity> findJgTree() {
        List<SysZcjgEntity> list = commomMapper
                .selectList(new LambdaQueryWrapper<SysZcjgEntity>().eq(SysZcjgEntity::getJlzt,"0")
                .orderByDesc(SysZcjgEntity::getPxxh));
        List<JgTreeEntity> result = new ArrayList<>();
        for (SysZcjgEntity entity : list) {
            JgTreeEntity newEntity = new JgTreeEntity();
            newEntity.setJgbm(entity.getJgbm());
            newEntity.setJgmc(entity.getJgmc());
            newEntity.setJgjc(entity.getJgjc());
            newEntity.setJgfl(entity.getJgfl());
            newEntity.setJglb(entity.getJglb());
            newEntity.setSjjgbm(entity.getSjjgbm());
            newEntity.setSjjgmc(entity.getSjjgmc());
            result.add(newEntity);
        }
        return result;
    }

    @Override
    public SysZcjgEntity getJgInfo(String jgbm) {
        return commomMapper.
                selectOne(new LambdaQueryWrapper<SysZcjgEntity>().eq(SysZcjgEntity::getJgbm, jgbm));
    }
}
